﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TestRunner.Common;
using TestRunner.Events;

namespace TestRunner.ViewModels
{
    public class CanvasViewModel : ViewModelBase
    {
        #region constructor

        public CanvasViewModel()
        {
            EventManager.evFontTypeChange += new EventHandler<FontFamilyEventArgs>(EventManager_evFontTypeChange);
            EventManager.evFillShapeChange += new EventHandler<ColorEventArgs>(EventManager_evFillShapeChange);
            EventManager.evFontColorShapeChange += new EventHandler<ColorEventArgs>(EventManager_evFontColorShapeChange);
            EventManager.evFontSizeChange += new EventHandler<FontSizeEventArgs>(EventManager_evFontSizeChange);
            EventManager.evTextAlignmentChange += new EventHandler<TestAligmentArgs>(EventManager_evTextAlignmentChange);
            EventManager.evBorderColorShapeChange += new EventHandler<ColorEventArgs>(EventManager_evBorderColorShapeChange);
            EventManager.evFontBold += new EventHandler<BoolEventArgs>(EventManager_evFontBold);
            EventManager.evFontItalic += new EventHandler<BoolEventArgs>(EventManager_evFontItalic);
            EventManager.evFontUnderline += new EventHandler<BoolEventArgs>(EventManager_evFontUnderline);
            EventManager.evBorderLineWidth += new EventHandler<DoubleEventArgs>(EventManager_evBorderLineWidth);
            EventManager.evBorderLineStyle += new EventHandler<DoubleCollectionEventArgs>(EventManager_evBorderLineStyle);
        }

        #endregion constructor

        #region Shape Font Family

        public FontFamily _shapeFontFamily = new FontFamily("Arial");
        public FontFamily ShapeFontFamily
        {
            get { return _shapeFontFamily; }
            set
            {
                _shapeFontFamily = value;
                RaisePropertyChanged("ShapeFontFamily");
            }

        }

        void EventManager_evFontTypeChange(object sender, FontFamilyEventArgs e)
        {
            ShapeFontFamily = e.SelectedFontFamily;
        }


        #endregion Shape Font Family

        #region Shape Font Size

        public double _shapeFontSize = 14;
        public double ShapeFontSize
        {
            get { return _shapeFontSize; }
            set
            {
                _shapeFontSize = value;
                RaisePropertyChanged("ShapeFontSize");
            }

        }

        void EventManager_evFontSizeChange(object sender, FontSizeEventArgs e)
        {
            ShapeFontSize = e.SelectedFontSize;
        }

        #endregion Shape Font Size

        #region Shape Text Aligment

        private HorizontalAlignment _shapeTextAligment = HorizontalAlignment.Center;

        public HorizontalAlignment ShapeTextAligment
        {
            get { return _shapeTextAligment; }
            set
            {
                _shapeTextAligment = value;

                // Whenever you choose a border style change the selected shape border style.
                // If we have this splitted into to different viewmodels we could use some eventing mechanism to communicate the new value
                //ShapeBorderStyle = _selectedBorderStyle;


                RaisePropertyChanged("ShapeTextAligment");
            }
        }

        void EventManager_evTextAlignmentChange(object sender, TestAligmentArgs e)
        {
            ShapeTextAligment = e.SelectedAlignment;
        }

        #endregion Shape Text Aligment

        #region Shape Border Style

        private DoubleCollection _shapeBorderStyle = new DoubleCollection();

        public DoubleCollection ShapeBorderStyle
        {
            get { return _shapeBorderStyle; }
            set
            {
                _shapeBorderStyle = value;

                RaisePropertyChanged("ShapeBorderStyle");
            }
        }

        void EventManager_evBorderLineStyle(object sender, DoubleCollectionEventArgs e)
        {
            ShapeBorderStyle = e.SelectedValue;
        }


        #endregion Shape Border Style

        #region Shape Border Thickness

        private double _shapeBorderThickness = 5;

        public double ShapeBorderThickness
        {
            get { return _shapeBorderThickness; }
            set
            {
                _shapeBorderThickness = value;

                RaisePropertyChanged("ShapeBorderThickness");
            }
        }


        void EventManager_evBorderLineWidth(object sender, DoubleEventArgs e)
        {
            ShapeBorderThickness = e.SelectedValue;
        }


        #endregion Shape Border Thickness

        #region Shape Font Weight

        private FontWeight _shapeFontWeight = FontWeights.Normal;

        public FontWeight ShapeFontWeight
        {
            get { return _shapeFontWeight; }
            set
            {
                _shapeFontWeight = value;

                RaisePropertyChanged("ShapeFontWeight");
            }
        }

        void EventManager_evFontBold(object sender, BoolEventArgs e)
        {
            ShapeFontWeight = (e.SelectedValue) ? FontWeights.Bold : FontWeights.Normal;
        }


        #endregion Shape Font Weight
       
        #region Shape Font Italic


        private FontStyle _shapeFontStyle = FontStyles.Normal;

        public FontStyle ShapeFontStyle
        {
            get { return _shapeFontStyle; }
            set
            {
                _shapeFontStyle = value;

                RaisePropertyChanged("ShapeFontStyle");
            }
        }

        void EventManager_evFontItalic(object sender, BoolEventArgs e)
        {
            ShapeFontStyle = (e.SelectedValue) ? FontStyles.Italic : FontStyles.Normal;
        }


        #endregion Shape Font Italic

        #region Shape Font Underlined

        private TextDecorationCollection _shapeFontDecoration = null;

        public TextDecorationCollection ShapeFontDecoration
        {
            get { return _shapeFontDecoration; }
            set
            {
                _shapeFontDecoration = value;

                RaisePropertyChanged("ShapeFontDecoration");
            }

        }

        void EventManager_evFontUnderline(object sender, BoolEventArgs e)
        {
            ShapeFontDecoration = (e.SelectedValue) ? TextDecorations.Underline : null;
        }


        #endregion Shape Font Underlined

        #region Shape Font Color

        private Color _shapeFontColor = Colors.White;

        public Color ShapeFontColor
        {
            get { return _shapeFontColor; }
            set
            {
                _shapeFontColor = value;
                RaisePropertyChanged("ShapeFontColor");
            }
        }

        void EventManager_evFontColorShapeChange(object sender, ColorEventArgs e)
        {
            ShapeFontColor = e.SelectedColor;
        }

        #endregion Shape Font Color

        #region Shape Background Color

        private Color _shapeBackgroundColor = Color.FromArgb(255, 84, 141, 212);

        public Color ShapeBackgroundColor
        {
            get { return _shapeBackgroundColor; }
            set
            {
                _shapeBackgroundColor = value;
                RaisePropertyChanged("ShapeBackgroundColor");
            }
        }

        void EventManager_evFillShapeChange(object sender, ColorEventArgs e)
        {
            ShapeBackgroundColor = e.SelectedColor;
        }

        #endregion Shape Background Color

        #region Shape Border Color

        private Color _shapeBorderColor = Color.FromArgb(255, 23, 54, 93);

        public Color ShapeBorderColor
        {
            get { return _shapeBorderColor; }
            set
            {
                _shapeBorderColor = value;
                RaisePropertyChanged("ShapeBorderColor");
            }
        }

        void EventManager_evBorderColorShapeChange(object sender, ColorEventArgs e)
        {
            ShapeBorderColor = e.SelectedColor;
        }
        
        #endregion Shape Border Color
    }
}
